﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfDrawing
{
    /// <summary>
    /// TanksWar.xaml 的交互逻辑
    /// </summary>
    public partial class TanksWar : Window
    {
        public TanksWar()
        {
            InitializeComponent();

            //timer.Interval = new TimeSpan(0, 0, 0, 0, 20);
            //timer.Tick += MoveHandler;
            //timer.IsEnabled = true;
            //timer.Start();

            //Rect rect = new Rect(50, 50, 100, 100);
            //mg.DrawingRender(rect);
        }

        //private void MoveHandler(object sender, EventArgs e)
        //{
        //    i++;
        //    Rect rc = DrawingVisualExtension.GetRect(mg);

        //    if (i<=1000)
        //    {
        //        rc.Offset(0.5, 0);
        //    }
        //    else if(1000 < i && i <= 2000)
        //    {
        //        rc.Offset(0, 0.5);
        //    }
        //    else if (2000 < i && i <= 3000)
        //    {
        //        rc.Offset(-0.5, 0);
        //    }
        //    else if (3000 < i && i <= 4000)
        //    {
        //        rc.Offset(0, -0.5);
        //    }
        //    else
        //    {
        //        i = 0;
        //    }


        //    mg.DrawingRender(rc);


        //}
        int i = 0;

        double speed = 3;

        DispatcherTimer timer = new DispatcherTimer();


        private bool KeyUpPress = false;
        private bool KeyDownPress = false;
        private bool KeyLeftPress = false;
        private bool KeyRightPress = false;

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            
            if (e.KeyboardDevice.IsKeyDown(Key.Up) )
            {
                KeyUpPress = true;
            }
            if(e.KeyboardDevice.IsKeyDown(Key.Down))
            {
                KeyDownPress = true;
                
            }
            if (e.KeyboardDevice.IsKeyDown(Key.Left))
            {
                KeyLeftPress = true;               
            }
            if (e.KeyboardDevice.IsKeyDown(Key.Right))
            {
                KeyRightPress = true;
            }
            e.Handled = true;

        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (!e.KeyboardDevice.IsKeyDown(Key.Up))
            {
                KeyUpPress = false;
            }
            if (!e.KeyboardDevice.IsKeyDown(Key.Down))
            {
                KeyDownPress = false;

            }
            if (!e.KeyboardDevice.IsKeyDown(Key.Left))
            {
                KeyLeftPress = false;
            }
            if (!e.KeyboardDevice.IsKeyDown(Key.Right))
            {
                KeyRightPress = false;
            }
            e.Handled = true;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.From = 50;
            da.To = 500;
            da.Duration = TimeSpan.FromSeconds(10);
            Timeline.SetDesiredFrameRate(da, 30);


            btn.BeginAnimation(Button.WidthProperty, da);
        }
    }
}
